static <- read.csv("../data/from_CW_via_Slack_20210507/StaticDF.csv", row.names=1)
static <- static[order(static$Culture_Type,static$Cell_Line),]
static[static$Cell_Conc==0,"Cell_Conc"] <- 1
cell_lines <- unique(static$Cell_Line)
static <- static[!(static$Cell_Line=="CORL279" & static$RLU < 10),]
par(mfrow=c(2,5))
linear_models <- lapply(cell_lines, function(cl) {
dat <- static[static$Cell_Line==cl,]
culture_type <- unique(dat$Culture_Type)
m <- lm(log2(RLU) ~ log2(Cell_Conc), data = dat)
plot(log2(RLU) ~ log2(Cell_Conc), data=dat, main=paste0(cl," (",culture_type,")"), xlim=c(0,14), ylim=c(7,18))
abline(m, col="blue")
return(m)
})
names(linear_models) <- cell_lines
Assuming first part of data is at some minimum value and not associated with any actual cell count (lower limit of detection), which would result in slope=0 (values are constant until some minimum number of cells is achieved).
lagLine <- function (x, lower, slope, br = 64) sapply(x, function(z) ifelse(z <= br, lower, lower + (z-br) * slope))
fitLagLin <- function(x, y, start_list=list(lower=5, slope=1, br=1))
nls(y ~ lagLine(x=x, lower, slope, br),
start = start_list,
algorithm="port",
control=nls.control(maxiter=500)
)
par(mfrow=c(2,5))
lag_linear_models <- lapply(cell_lines, function(cl) {
m <- tryCatch({
dat <- static[static$Cell_Line==cl,]
culture_type <- unique(dat$Culture_Type)
m <- fitLagLin(log2(dat$Cell_Conc), log2(dat$RLU))
}, error=function(e) { return(e) })
# if(culture_type == "Adherent")
# {
# xr <- c(4,12)
# } else {
# xr <- c(6,14)
# }
xr <- c(0,14)
plot(log2(RLU) ~ log2(Cell_Conc), data=dat, main=paste0(cl," (",culture_type,")"), xlim=xr, ylim=c(7,18))
if(class(m)[1] != "nls")
{
m <- lm(log2(RLU) ~ log2(Cell_Conc), data=dat[dat$Cell_Conc>1,])
abline(m, col="blue", lwd=2)
} else {
curve(from=0.5,to=18, lagLine(x, lower=coef(m)['lower'],
slope=coef(m)['slope'],
br=coef(m)['br']),
col="blue", lwd=2, add=TRUE)
}
# text(12, 9, paste("Adj R2 ="))
return(m)
})
names(lag_linear_models) <- cell_lines
Assume all luminescence values with cells produce detectable signal.
par(mfrow=c(2,5))
linear_models <- lapply(cell_lines, function(cl) {
dat <- static[static$Cell_Line==cl & static$Cell_Conc >1,]
culture_type <- unique(dat$Culture_Type)
m <- lm(log2(RLU) ~ log2(Cell_Conc), data = dat)
plot(log2(RLU) ~ log2(Cell_Conc), data=dat, main=paste0(cl," (",culture_type,")"), xlim=c(0,14), ylim=c(7,18))
abline(m, col="blue")
return(m)
})
names(linear_models) <- cell_lines
Assuming the lowest number of cells is above the threshold of detection, will remove the no cells control and fit remaining data.
dat <- static[static$Cell_Conc > 1,]
m2 <- lme4::lmList(log2(RLU) ~ log2(Cell_Conc) | Cell_Line, data=dat)
f2 <- coef(m2)
r2 <- unlist(summary(m2)$adj.r.squared)
par(mfrow=c(2,5))
temp <- lapply(cell_lines, function(cl) {
dtp <- dat[dat$Cell_Line==cl,]
culture_type <- unique(dtp[dtp$Cell_Line==cl,'Culture_Type'])
if(culture_type == "Adherent")
{
xr <- c(5,12)
} else {
xr <- c(7,14)
}
plot(log2(RLU) ~ log2(Cell_Conc),
data=dtp,
main=paste0(cl," (",culture_type,")"),
xlim=xr, ylim=c(7,18))
abline(m2[[cl]], col="blue", lwd=2)
text(xr[1]+0.25, 17, pos=4, paste("slope =",signif(f2[cl,2],3)))
text(xr[1]+0.25, 16, pos=4, expression(R^2))
text(xr[1]+1, 16, pos=4, paste("=", signif(r2[cl],3)))
})
fitLagLin1 <- function(x, y, start_list=list(lower=5, br=1))
nls(y ~ lagLine(x=x, lower, slope=1, br),
start = start_list,
algorithm="port",
control=nls.control(maxiter=500)
)
par(mfrow=c(2,5))
lag_linear1_models <- lapply(cell_lines, function(cl) {
m <- tryCatch({
dat <- static[static$Cell_Line==cl,]
culture_type <- unique(dat$Culture_Type)
m <- fitLagLin1(log2(dat$Cell_Conc), log2(dat$RLU))
}, error=function(e) { return(e) })
# if(culture_type == "Adherent")
# {
# xr <- c(4,12)
# } else {
# xr <- c(6,14)
# }
xr <- c(0,14)
plot(log2(RLU) ~ log2(Cell_Conc), data=dat, main=paste0(cl," (",culture_type,")"), xlim=xr, ylim=c(7,18))
if(class(m)[1] != "nls")
{
m <- lm(log2(RLU) ~ log2(Cell_Conc), data=dat[dat$Cell_Conc>1,])
abline(m, col="blue", lwd=2)
} else {
curve(from=0.5,to=18, lagLine(x, lower=coef(m)['lower'],
slope=1,
br=coef(m)['br']),
col="blue", lwd=2, add=TRUE)
}
# text(12, 9, paste("Adj R2 ="))
return(m)
})
names(lag_linear1_models) <- cell_lines
lcc_cell_lines <- unique(lcc$cell.line)
ctrls <- lapply(lcc_cell_lines, function(cl) lcc[lcc$cell.line==cl & lcc$drug1.conc==0,])
names(ctrls) <- lcc_cell_lines
par(mfrow=c(2,2))
invisible(lapply(names(ctrls), function(n) do.call(plotGC,
append(getGCargs(ctrls[[n]], dat.col=c("time","Cell_Count","uid")),list(main=n, leg=FALSE)))))
par(mfrow=c(2,2))
invisible(lapply(names(ctrls), function(n) do.call(plotGC,
append(getGCargs(ctrls[[n]], dat.col=c("time","RLU","uid")),list(main=n)))))
dms53 <- ctrls[['DMS53']]
par(mfrow=c(1,2))
invisible(do.call(plotGC, append(getGCargs(dms53),list(main="DMS53, cell count", leg=FALSE))))
invisible(do.call(plotGC, append(getGCargs(dms53, dat.col=c("time","RLU","uid")),list(main="DMS53, lum", leg=FALSE))))
h1048 <- ctrls[['H1048']]
par(mfrow=c(1,2))
invisible(do.call(plotGC, append(getGCargs(h1048, dat.col=c("time","Cell_Count","uid")),list(main="H1048, cell count", leg=FALSE))))
invisible(do.call(plotGC, append(getGCargs(h1048, dat.col=c("time","RLU","uid")),list(main="H1048, lum", leg=FALSE))))
invisible(do.call(plotGC, append(getGCargs(h1048, dat.col=c("time","RLU","uid")),list(main="H1048, lum", leg=FALSE))))
lines(log2(cell.count)-log2(cell.count)[1] ~ time, data=h1048_sumc, lwd=3)